<?php

namespace app\api\controller;

use app\traits\HttpResponse;
use think\Controller;
use think\Request;

class Base extends Controller
{
    use HttpResponse;

    protected $request;


    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    public function user()
    {
        //获取token
        $token = $this->request->header('Authorization');
        if (!$token) $this->exitJson('登陆过期，请重新登陆', 9001);
        $user = \app\common\model\User::where('token', $token)->find();
        if (!$user) $this->exitJson('登陆过期，请重新登陆', 9001);
        if ($user->exp_time < time()) $this->exitJson('登陆过期，请重新登陆', 9001);
        return $user;
    }


}
